package org.example.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 还款计划实体类
 * 包含每笔订单的还款计划信息
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("mall_repay_plan")
public class MallRepayPlan implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 下单订单号
     */
    @TableField("order_number")
    private String orderNumber;

    /**
     * 期数
     */
    @TableField("period_number")
    private Integer periodNumber;

    /**
     * 到期时间
     */
    @TableField("due_time")
    private LocalDateTime dueTime;

    /**
     * 实还时间
     */
    @TableField("actual_repay_time")
    private LocalDateTime actualRepayTime;

    /**
     * 还款状态(1在途2正常还款3逾期还款)
     */
    @TableField("repay_status")
    private Integer repayStatus;

    /**
     * 逾期天数
     */
    @TableField("overdue_days")
    private Integer overdueDays;

    /**
     * 应收本金
     */
    @TableField("principal_receivable")
    private BigDecimal principalReceivable;

    /**
     * 创建时间
     */
    @TableField("create_time")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField("update_time")
    private LocalDateTime updateTime;

    /**
     * 还款状态枚举
     */
    public enum RepayStatus {
        IN_TRANSIT(1, "在途"),
        NORMAL_REPAY(2, "正常还款"),
        OVERDUE_REPAY(3, "逾期还款");

        private final Integer code;
        private final String desc;

        RepayStatus(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        public static RepayStatus fromCode(Integer code) {
            for (RepayStatus status : values()) {
                if (status.getCode().equals(code)) {
                    return status;
                }
            }
            return null;
        }
    }
}
